import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

// const state = {
//     count:0
// }

function storeLocalStore (state) {
  window.localStorage.setItem("userinfo", JSON.stringify(state));
}

export default new Vuex.Store({
  // state

  state: {
    count: 0,
    userinfo: {}

  },
  // set方法
  mutations: {
    increment: state => state.count++,
    decrement: state => state.count--,
    //这里是set方法，比如对该数据的修改、增加、删除等等。
    //组件调用this.$store.commit('SET_TOKEN','new token')挂载方法
    // SET_TOKEN: (state, token) => {
    //   state.token = token
    //   console.log(state.token);
    // },
    SET_USERINFO: (state, userinfo) => {
      state.userinfo = userinfo
      storeLocalStore(state)
      console.log("传入", state.userinfo);
    }
  },
  // get方法
  getters: {
    token: state => state.token,
    userinfo: state => state.userinfo
  }
})